<template>
  <div class="login-container">
    <div class="head">
      <span>登录</span>
      <span>Login</span>
    </div>
    <main>
      <div class="main-head">
        <span :class="{active:flag===1}" @click="doActive(1)">支付宝登录</span>
        <span :class="{active:flag===2}" @click="doActive(2)">手机号登录</span>
      </div>
      <div class="mode1" v-show="show">
        <img src="../images/alipaycode.png" alt="支付宝码">
        <p>请使用手机支付宝扫码</p>
      </div>
      <div class="mode2" v-show="!show">
        <div class="item">
          <img src="../images/phone.png" alt>
          <input type="text" placeholder="手机号">
        </div>
        <div class="item">
          <img src="../images/mima.png" alt>
          <input type="password" placeholder="密码">
        </div>
        <div class="forget">忘记密码</div>
        <div class="foot">
          <button>登录</button>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { isBlank } from '@/utils/validate'
export default {
  name: 'Login',
  data() {
    return {
      flag:1,
      show:true
    }
    const validateUsername = (rule, value, callback) => {
      if (isBlank(value)) {
        callback(new Error('请输入正确的用户名'))
      } else {
        callback()
      }
    };
    const validatePass = (rule, value, callback) => {
      if (isBlank(value)) {
        callback(new Error('密码不能为空'))
      } else {
        callback()
      }
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    doActive: function(a) {
      this.flag = a; //点哪个显示哪个
      if (this.flag === 2) {
        this.show = false;
      } else {
        this.show = true;
      }
    },
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store.dispatch('Login', this.loginForm).then(() => {
            this.loading = false;
            this.$router.push({ path: this.redirect || '/' })
          }).then(() => {
            // this.$store.dispatch('QueryMenus');// permission.js中18行与此操作重复，故注掉
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!');
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background-image: url(../images/bg.png);
  background-size: 100% 100%;
  .head{
    width: 200px;
    height: 50px;
    position: absolute;
    top: 17%;
    left: 26%;
    font-size: 34px;
    color: #393939;
    span:last-of-type{
      color: #ccc;
      font-size: 30px;
      border-left: 2px solid #ccc;
      padding: 0 20px;
      margin-left: 10px;
    }
  }
}
main{
  width: 370px;
  height: 410px;
  background-color: #fff;
  position: absolute;
  top: 25%;
  left: 26%;
  box-shadow:0 0 20px #ddd;
  .main-head{
    width: 100%;
    height: 60px;
    border-bottom: 1px solid #e5e5e5;
    color: #b3b3b3;
    font-size: 22px;
    line-height: 60px;
    padding: 0 40px;
    span{
      display: inline-block;
      width: auto;
      height: 100%;
      text-align: center;
      margin-right: 50px;
    }
    span:last-of-type{
      margin-right: 0;
    }
    .active{
      color: #5abafd;
      border-bottom: 4px solid #5abafd;
    }
  } 
  .mode1{
    width: 49%;
    height: 45%;
    text-align: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    img{
      width: 140px;
    }
    p{
      color: #b3b3b3;
      font-size: 18px;
    }
  }
  .mode2{
    width: 100%;
    height: 100%;
    padding: 50px 30px;
    .item{
      width: 100%;
      height: 50px;
      margin-bottom: 35px;
      position: relative;
      img{
        position: absolute;
        top: 15px;
        left: 18px;
      }
      input{
        width: 100%;
        height: 100%;
        padding-left: 50px;
        outline: none;
        color: #b4b4b4;
        border: 1px solid rgba(0, 0, 0, 0.1);
      }
    }
    .item:nth-child(2){
      margin-bottom: 0;
    }
    .forget{
      width: auto;
      float: right;
      margin-top: 8px;
      color: #5abafd;
      font-size: 16px;
    }
    .foot{
      width: 100%;
      height: 55px;
      margin-top: 55px;
      button{
        width: 100%;
        height: 100%;
        background-color: #5abafd;
        border: none;
        outline: none;
        color: #fff;
        font-size: 22px;
      }
    }
  }
}
</style>
